package com.source.lightfowl.basedata.controller;

import com.source.lightfowl.VO.PoultryChartVO;
import com.source.lightfowl.VO.PoultrySalesVO;
import com.source.lightfowl.basedata.service.PoultrySalesChartService;
import com.source.lightfowl.utils.MyResult;
import com.source.lightfowl.utils.StatusCode;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Description:
 * @Author: Faink
 * @CreateTime: 2020/9/11 19:39
 */
@Api(tags = "禽类贴标销售图表集")
@CrossOrigin
@RestController
@RequestMapping(value = "/PoultrySales")
public class PoultrySalesController {

    @Autowired
    private PoultrySalesChartService poultrySalesChartService;

    @ApiOperation(value = "查找销售去向 by市场")
    @GetMapping("/findAll/chart/by/house")
    public MyResult findAllSales(int house_id) {
        List<PoultrySalesVO> vos = poultrySalesChartService.findAllSales(house_id);
//        System.out.println(vos.get(0).toString());
        return MyResult.build(0, "操作成功", vos);
    }

    @ApiOperation(value = "查找销售去向回显 byid")
    @GetMapping("/findAll/chart/by/id")
    public MyResult findAllSalesById(String id) {
        List<PoultrySalesVO> vos = poultrySalesChartService.findAllSalesById(id);
        return MyResult.build(0, "操作成功", vos);
    }

    @ApiOperation(value = "查找销售去向 by脚标机id")
    @GetMapping("/findAll/by/barcodeId")
    public MyResult findAllRecordSales(int barcodeMachineId) {
        return MyResult.build(0, "操作成功", poultrySalesChartService.findAllRecordTo(barcodeMachineId));
    }

    @ApiOperation(value = "查找销售去向-用于柱状图(暂只用于禽类状态表)")
    @GetMapping("/findAll/bar/by/house")
    public MyResult findAllSalesToPieChart(int house_id) {
        List<PoultryChartVO> vos = poultrySalesChartService.findAllSalesData(house_id);
        return MyResult.build(0, "操作成功", vos);
    }

    @ApiOperation(value = "搜索所有父级禽类名")
    @GetMapping("/findAll/parent")
    public MyResult findAllPoultryParent() {
        return MyResult.build(StatusCode.SUCCESS, "操作成功", poultrySalesChartService.findAllParent());
    }

    @ApiOperation(value = "搜索所有子禽类名 by 父级id")
    @ApiImplicitParam(name = "id", value = "父级id", required = true)
    @GetMapping("/findAll/by/parent")
    public MyResult findPoultryByParent(String id) {
        return MyResult.build(StatusCode.SUCCESS, "操作成功", poultrySalesChartService.findPoultryByParentId(id));
    }

    @ApiOperation(value = "查出本市场中各父级禽类共累计卖出量")
    @ApiImplicitParam(name = "houseId", value = "市场id", required = true)
    @GetMapping("/findCountOfParent/by/house")
    public MyResult findCountOfParentInHouse(int houseId) {
        return MyResult.build(StatusCode.SUCCESS, "操作成功", poultrySalesChartService.findCountOfParent(houseId));
    }

    @ApiOperation(value = "查出今年本市场中各父级禽类共累计卖出量")
    @ApiImplicitParam(name = "houseId", value = "市场id", required = true)
    @GetMapping("/findCountOfParentThisYear/by/house")
    public MyResult findCountOfParentInHouseThisYear(int houseId) {
        return MyResult.build(StatusCode.SUCCESS, "操作成功", poultrySalesChartService.findCountOfParentThisYear(houseId));
    }

    @ApiOperation(value = "按年制返回该市场父级禽类销量")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "parentId", value = "父级禽类id", required = true),
            @ApiImplicitParam(name = "houseId", value = "市场id", required = true)
    })
    @GetMapping("/findCountOfParent/by/year")
    public MyResult findCountOfParentInYear(String parentId, int houseId) {
        return MyResult.build(StatusCode.SUCCESS, "操作成功", poultrySalesChartService.findSalesInYears(parentId, houseId));
    }

    @ApiOperation(value = "查找父级禽类销量情况-一个月/10天-用于Bar图（简单测试案例成功）")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "houseId", value = "市场id", required = true),
            @ApiImplicitParam(name = "parentId", value = "父级id or all(表示所有禽类)", required = true, defaultValue = "")
    })
    @GetMapping("/findSaleOfParent/to/barchart")
    public MyResult findParentSaleTenDaysOfMonthAgo(int houseId, String parentId) {
        return MyResult.build(StatusCode.SUCCESS, "操作成功", poultrySalesChartService.findParentSalesDataTenDaysOfMonthAgo(houseId, parentId));
    }

    @ApiOperation(value = "（统计包含了所有宰杀市场）今年父禽类销量占比饼图")
    @GetMapping("/findSaleOfParent/to/piechart")
    public MyResult findSaleCountThisYear() {
        return MyResult.build(StatusCode.SUCCESS, "操作成功", poultrySalesChartService.findSaleCountThisYear());
    }

    @ApiOperation(value = "选定市场->今年父禽类销量占比饼图")
    @ApiImplicitParam(name = "houseId", value = "市场id", required = true)
    @GetMapping("/findSaleOfParent/to/piechart/by/house")
    public MyResult findSaleCountThisYearByHouse(int houseId) {
        return MyResult.build(StatusCode.SUCCESS, "操作成功", poultrySalesChartService.findSaleCountThisYear(houseId));
    }

    @ApiOperation(value = "选定市场->迄今为止父禽类销量")
    @ApiImplicitParam(name = "houseId", value = "市场id", required = true)
    @GetMapping("/findSaleOfParent/by/house")
    public MyResult findSaleCountsByHouse(int houseId) {
        return MyResult.build(StatusCode.SUCCESS, "操作成功", poultrySalesChartService.findSaleCount(houseId));
    }

    @ApiOperation(value = "选定某个市场 ->各个父级禽类的销量by月-用于折线图")
    @ApiImplicitParam(name = "houseId", value = "市场id", required = true)
    @GetMapping("/findSaleOfParent/to/linechart")
    public MyResult findSaleOfParentByHouseInMonth(int houseId) {
        return MyResult.build(StatusCode.SUCCESS, "操作成功", poultrySalesChartService.findSaleOfParentByHouseInMonth(houseId));
    }

    @ApiOperation(value = "查找前三个月每个月的销售冠军市场-用于柱状图")
    @GetMapping("/findMaxHouse/to/table")
    public MyResult findMaxSalesThreeMonthAgo() {
        return MyResult.build(StatusCode.SUCCESS, "操作成功", poultrySalesChartService.findMaxSalesHouseThreeMonthAgo());
    }

    @ApiOperation(value = "选定某个市场为源 ->向去向市场的某禽类交易量排名（前一个月）-用于首页禽类销售状态表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "houseId", value = "市场id", required = true),
            @ApiImplicitParam(name = "parentId", value = "父级id or all(表示所有禽类)", required = true, defaultValue = "")
    })
    @GetMapping("/findMarkSort/order/by/sale")
    public MyResult findBestSaleMarketSort(int houseId, String parentId) {
        return MyResult.build(StatusCode.SUCCESS, "操作成功", poultrySalesChartService.findBestSaleOfMarketOneMonthsAgo(houseId, parentId));
    }

    @ApiOperation(value = "选定源头市场 ->找到有交易的去向市场并显示源头市场的销量、去向市场成交量-用于关系图与地图")
    @ApiImplicitParam(name = "houseId", value = "市场id", required = true)
    @GetMapping("/findRelation/in/year")
    public MyResult findRelationOfHouseInThisYear(int houseId) {
        return MyResult.build(StatusCode.SUCCESS, "操作成功", poultrySalesChartService.findRelationOfHouseInThisYear(houseId));
    }

    @ApiOperation(value = "贴标历史查询 ->默认查找全部档口在近一个月内的贴标数 简单测试access")
    @GetMapping("/findDefaultCountsByTime")
    public MyResult findDefaultCountsByTime() {
        return MyResult.build(StatusCode.SUCCESS, "操作成功", poultrySalesChartService.findDefaultCount());
    }

    @ApiOperation(value = "贴标历史查询 ->默认查找全部档口在近一个月内的每个父级禽类贴标数(每单天) 简单测试access")
    @GetMapping("/findDefaultCountsByTimeInDays")
    public MyResult findDefaultCountsByTimeInDays() {
        return MyResult.build(StatusCode.SUCCESS, "操作成功", poultrySalesChartService.findDefaultCountByDays());
    }

    @ApiOperation(value = "贴标历史查询 ->根据档口名字或者联系人的名字模糊匹配 查询某个时间段各父级贴标的数量 简单测试access")
    @GetMapping("/findCountByNameAndTime")
    public MyResult findCountByNameAndTime(String stallName,String linkName,String startDate,String endDate) {
        return MyResult.build(StatusCode.SUCCESS, "操作成功", poultrySalesChartService.findCountByNameAndTime(stallName, linkName, startDate, endDate));
    }

    @ApiOperation(value = "贴标历史查询 ->根据档口名字或者联系人的名字模糊匹配 查询某个时间段各父级贴标的数量(每天) 简单测试access")
    @GetMapping("/findCountByNameAndTimeByDays")
    public MyResult findCountByNameAndTimeByDays(String stallName,String linkName,String startDate,String endDate) {
        return MyResult.build(StatusCode.SUCCESS, "操作成功", poultrySalesChartService.findCountByNameAndTimeByDays(stallName, linkName, startDate, endDate));
    }

}
